//
//  MeInfoViewMode.m
//  fitness-iOS
//
//  Created by 卢仕彤 on 2017/11/10.
//  Copyright © 2017年 卢仕彤. All rights reserved.
//

#import "MeInfoViewMode.h"
#import "FFGlobalHeader.h"
#import "UIImageView+RoundImage.h"
#import "UIImageView+WebCache.h"

@implementation MeInfoViewMode

@end


@interface MeHeadInfoCell ()

@property (nonatomic, strong) UIImageView *headIconView;
@property (nonatomic, strong) UILabel *userNameLabel;
@property (nonatomic, strong) UILabel *fanNumberLabel;
@property (nonatomic, strong) UILabel *followNumberLabel;
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) UILabel *dynamicLabel;

@end

@implementation MeHeadInfoCell

- (void)setMode:(MeinfoMode *)mode {
    _mode = mode;
    _userNameLabel.text = mode.nickname;
    
    _fanNumberLabel.text = [NSString stringWithFormat:@"%@ 粉丝",mode.fans_count];
    _followNumberLabel.text = [NSString stringWithFormat:@"%@ 关注",mode.follow_count];
    _dynamicLabel.text = [NSString stringWithFormat:@"%@ 动态",mode.status];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = [UIColor colorWithHexString:@"#453C4C"];
    [self.contentView addSubview:[self headIconView]];
    self.headIconView.layer.cornerRadius = 30;
    
    NSString *info_url_syring = @"http://touchfit.oss-cn-qingdao.aliyuncs.com/headimg/14/%E5%A4%B4%E5%83%8F.png";
    [self.headIconView ff_setImageUrl:[NSURL URLWithString:info_url_syring] placeholder:[UIImage imageNamed:@"img_personal_head"] size:CGSizeMake(80, 80) cornerRadius:40 borderWidth:4 borderColor:@"#FFFFFF"];
    
    
    [self.headIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left).offset(30);
        make.centerY.equalTo(self.contentView.centerY);
        make.size.equalTo(@(80));
    }];
    
    
    [self.contentView addSubview:[self userNameLabel]];
    self.userNameLabel.textAlignment = NSTextAlignmentLeft;
    [self.userNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headIconView.right).offset(15);
        make.top.equalTo(self.headIconView.top).offset(10);
    }];
    
    [self.contentView addSubview:[self fanNumberLabel]];
    [self.fanNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.userNameLabel.left);
        make.bottom.equalTo(self.headIconView.bottom).offset(-10);
    }];
    
    UIImageView *circleImage = [UIImageView new];
    [self.contentView addSubview:circleImage];
    circleImage.backgroundColor = [UIColor whiteColor];
    circleImage.layer.cornerRadius = 2;
    [circleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.fanNumberLabel.right).offset(10);
        make.centerY.equalTo(self.fanNumberLabel.centerY);
        make.size.equalTo(CGSizeMake(4, 4));
    }];
    
    [self.contentView addSubview:[self followNumberLabel]];
    [self.followNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(circleImage.right).offset(10);
        make.top.equalTo(self.fanNumberLabel.top);
    }];
    
    UIImageView *circleImage1 = [UIImageView new];
    [self.contentView addSubview:circleImage1];
    circleImage1.backgroundColor = [UIColor whiteColor];
    circleImage1.layer.cornerRadius = 2;
    [circleImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.followNumberLabel.right).offset(10);
        make.centerY.equalTo(self.followNumberLabel.centerY);
        make.size.equalTo(CGSizeMake(4, 4));
    }];
    
    [self.contentView addSubview:self.dynamicLabel];
    [self.dynamicLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(circleImage1.right).offset(10);
        make.top.equalTo(self.followNumberLabel.top);
    }];
    
}
#pragma -mark lazy init

- (UIImageView *)headIconView {
    if (!_headIconView) {
        _headIconView = [UIImageView new];
    }
    return _headIconView;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [UIImageView new];
    }
    return _arrowImageView;
}
- (UILabel *)userNameLabel {
    if (!_userNameLabel) {
        _userNameLabel = [UILabel labelWithSystemFontSize:22 textColorHexString:@"#FFFFFF"];
        _userNameLabel.font = [UIFont boldSystemFontOfSize:22];
    }
    return _userNameLabel;
}

- (UILabel *)fanNumberLabel {
    if (!_fanNumberLabel) {
        _fanNumberLabel = [UILabel labelWithSystemFontSize:12 textColorHexString:@"#FFFFFF"];
        _fanNumberLabel.text = @"100 粉丝";
    }
    return _fanNumberLabel;
}

- (UILabel *)followNumberLabel {
    if (!_followNumberLabel) {
        _followNumberLabel = [UILabel labelWithSystemFontSize:11 textColorHexString:@"#FFFFFF"];
         _followNumberLabel.text = @"100 关注数";
    }
    return _followNumberLabel;
}

- (UILabel *)dynamicLabel {
    if (!_dynamicLabel) {
        _dynamicLabel = [UILabel labelWithSystemFontSize:11 textColorHexString:@"#FFFFFF"];
        _dynamicLabel.text = @"10 动态";
    }
    return _dynamicLabel;
}


@end

@interface MeCenterCell ()

@property (nonatomic, strong) UIImageView *rightImageView;
@property (nonatomic, strong) UILabel *circleLabel;
@property (nonatomic, strong) UILabel *leftInfoLabel;

@end

@implementation MeCenterCell

- (UIImageView *)rightImageView {
    if (!_rightImageView) {
        _rightImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right_arrow"]];
        _rightImageView.contentMode = UIViewContentModeCenter;
    }
    return _rightImageView;
}

- (UILabel *)circleLabel {
    if (!_circleLabel) {
        _circleLabel =  [UILabel labelWithSystemFontSize:14 textColorHexString:@"#666666"];
    }
    return _circleLabel;
}

- (UILabel *)leftInfoLabel {
    if (!_leftInfoLabel) {
        _leftInfoLabel = [UILabel labelWithSystemFontSize:15 textColorHexString:@"#333333"];
    }
    return _leftInfoLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    [self.contentView addSubview:self.leftInfoLabel];
    self.leftInfoLabel.text = @"勋章";
    [_leftInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.centerY);
        make.left.equalTo(self.contentView.left).offset(15);
    }];
    
    [self.contentView addSubview:self.rightImageView];
    [_rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.right.equalTo(self.contentView.mas_right).offset(-15);
        make.size.mas_equalTo(CGSizeMake(22, 22));
    }];
    
    [self.contentView addSubview:self.circleLabel];
    self.circleLabel.text = @"0";
    [_circleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_rightImageView.centerY);
        make.right.equalTo(_rightImageView.mas_left).offset(-10);
    }];
    
}

@end

@interface MeDynamicCell ()

@property (nonatomic, strong) UIButton *bodyButon;
@property (nonatomic, strong) UIImageView *bodyImageView;
@property (nonatomic, strong) UILabel *bodyLabel;

@property (nonatomic, strong) UIButton *recordButton;
@property (nonatomic, strong) UIImageView *recordImageView;
@property (nonatomic, strong) UILabel *recordLabel;

@property (nonatomic, strong) UIButton *baseInfoButton;
@property (nonatomic, strong) UIImageView *baseInfoImageView;
@property (nonatomic, strong) UILabel *baseInfoLabel;

@end

@implementation MeDynamicCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    
    [self.contentView addSubview:self.bodyButon];
    [_bodyButon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.left);
        make.top.equalTo(self.contentView.top);
        make.width.equalTo(Main_Screen_Width/3);
        make.height.equalTo(Main_Screen_Width/3);
    }];
    
    [self.contentView addSubview:self.bodyImageView];
    [_bodyImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_bodyButon.centerX);
        make.centerY.equalTo(_bodyButon.centerY).offset(-10);
        make.size.equalTo(CGSizeMake(40, 40));
    }];
    
    [self.contentView addSubview:self.bodyLabel];
    [_bodyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_bodyImageView.centerX);
        make.top.equalTo(_bodyImageView.bottom).offset(15);
    }];
    
    [self.contentView addSubview:self.recordButton];
    [_recordButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bodyButon.right);
        make.top.equalTo(self.contentView.top);
        make.width.equalTo(Main_Screen_Width/3);
        make.height.equalTo(Main_Screen_Width/3);
    }];
    
    [self.contentView addSubview:self.recordImageView];
    [_recordImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_recordButton.centerX);
        make.centerY.equalTo(_recordButton.centerY).offset(-10);
        make.size.equalTo(CGSizeMake(40, 40));
    }];
    
    [self.contentView addSubview:self.recordLabel];
    [_recordLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_recordImageView.centerX);
        make.top.equalTo(_recordImageView.bottom).offset(15);
    }];
    
    
    [self.contentView addSubview:self.baseInfoButton];
    [_baseInfoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView.right);
        make.top.equalTo(self.contentView.top);
        make.width.equalTo(Main_Screen_Width/3);
        make.height.equalTo(Main_Screen_Width/3);
    }];
    
    [self.contentView addSubview:self.baseInfoImageView];
    [_baseInfoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_baseInfoButton.centerX);
        make.centerY.equalTo(_baseInfoButton.centerY).offset(-10);
        make.size.equalTo(CGSizeMake(40, 40));
    }];
    
    [self.contentView addSubview:self.baseInfoLabel];
    [_baseInfoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_baseInfoImageView.centerX);
        make.top.equalTo(_baseInfoImageView.bottom).offset(15);
    }];
    
}

-(UIButton *)bodyButon {
    if (!_bodyButon) {
        _bodyButon = [UIButton buttonWithType:UIButtonTypeCustom];
        _bodyButon.tag = 101;
        [_bodyButon addTarget:self action:@selector(clickMeBaseActionButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _bodyButon;
}

- (UIImageView *)bodyImageView {
    if (!_bodyImageView) {
        _bodyImageView = [UIImageView new];
        _bodyImageView.image = [UIImage imageNamed:@"me_body_info_button_pic"];
    }
    return _bodyImageView;
}

- (UILabel *)bodyLabel {
    if (!_bodyLabel) {
        _bodyLabel = [UILabel labelWithSystemFontSize:13 textColorHexString:@"#333333"];
        _bodyLabel.text = @"身体档案";
    }
    return _bodyLabel;
}

- (UIButton *)recordButton{
    if (!_recordButton) {
        _recordButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _recordButton.tag = 102;
        [_recordButton addTarget:self action:@selector(clickMeBaseActionButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _recordButton;
}

- (UIImageView *)recordImageView {
    if (!_recordImageView) {
        _recordImageView = [UIImageView new];
        _recordImageView.image = [UIImage imageNamed:@"me_record_button_pic"];
    }
    return _recordImageView;
}

- (UILabel *)recordLabel {
    if (!_recordLabel) {
        _recordLabel = [UILabel labelWithSystemFontSize:13 textColorHexString:@"#333333"];
        _recordLabel.text = @"训练记录";
    }
    return _recordLabel;
}

- (UIButton *)baseInfoButton {
    if (!_baseInfoButton) {
        _baseInfoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _baseInfoButton.tag = 103;
        [_baseInfoButton addTarget:self action:@selector(clickMeBaseActionButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _baseInfoButton;
}

- (UIImageView *)baseInfoImageView {
    if (!_baseInfoImageView) {
        _baseInfoImageView = [UIImageView new];
        _baseInfoImageView.image = [UIImage imageNamed:@"me_baseInfo_button_pic"];
    }
    return _baseInfoImageView;
}

- (UILabel *)baseInfoLabel {
    if (!_baseInfoLabel) {
        _baseInfoLabel = [UILabel labelWithSystemFontSize:13 textColorHexString:@"#333333"];
        _baseInfoLabel.text = @"基础信息";
    }
    return _baseInfoLabel;
}

#pragma -mark ------------------delegate----------------------

- (void)setDelegate:(id<MeinfoClickDelegate>)delegate {
    _delegate = delegate;
}

- (void)clickMeBaseActionButton:(UIButton *)clickButton {
    if (_delegate && [self.delegate respondsToSelector:@selector(clickMeBaseActionButton:)]) {
        [_delegate clickMeBaseActionButton:clickButton];
    }
}
@end

